Skip to main content
This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal

HCL Notes/Domino 8.5 Forum (includes Notes Traveler)

HCL Notes/Domino 8.5 Forum (includes Notes Traveler)

Previous Next
Subject: Notes Document to PDF
Feedback Type: Suggestion
Product Area: Notes Client
Technical Area: Application Development
Platform: ALL
Release: 8.5.3
Reproducible: Not applicable

So I found an article about converting a notes document to a pdf file..

http://www.reisinger.ws/2013/07/12/convert-lotus-notes-documents-to-pdfs-with-lotusscript-and-microsoft-word/

And I was able to get it to work.. but any in-line images are not brought into the pdf file.

Any suggestions..

here is the code:

pdfConverter Script Library

Options
%REM
Library PdfConverter
Created Sep 9, 2016 by Betsy Thiede/DEV/SPRGFLD/CSCI
Description: Comments for Library
%END REM
Option Public
Option Declare
Use "OpenLogFunctions"

Declarations
Const APIModule = "NNOTES"
Const wdExportFormatPDF = 17
Const wdExportFormatXPS = 18
Const wdExportOptimizeForOnScreen = 1
Const wdExportOptimizeForPrint = 0
Const wdExportAllDocument = 0
Const wdExportCurrentPage = 2
Const wdExportFromTo = 3
Const wdExportSelection = 1
Const wdExportDocumentContent = 0
Const wdExportDocumentWithMarkup = 7
Const wdExportCreateHeadingBookmarks = 1
Const wdExportCreateNoBookmarks = 0
Const wdExportCreateWordBookmarks = 2
Declare Function MailGetMessageBodyComposite Lib APIModule Alias "MailGetMessageBodyComposite" ( ByVal hNT As Long, ByVal N As String, ByVal D As String, nD As Long) As Integer
Declare Function ExportRTF Lib "nxrtf" Alias "ExportRTF" (ByVal sTempFile As String, ByVal flags As Long, hmod As Long, ByVal altlibrary As String, ByVal sRTFFile As String) As Integer

%REM
Sub ConvertDocToRtfFile
Description: Converts a NotesDocument to an RTF-Document and saves it under the filePath
Generates and removes some temporary Files while Working
%END REM
Public Sub ConvertDocToRtfFile(doc As NotesDocument, filePath As String)
Dim tempDoc As NotesDocument
Dim tempRti As NotesRichTextItem
' On Error GoTo ErrorHandler
Set tempDoc = doc.ParentDatabase.CreateDocument()
Set tempRti = tempDoc.CreateRichTextItem("Body")

Call doc.RenderToRTItem(tempRti)
Call ConvertItemToRtfFile(tempRti, filePath)
Exit Sub
ErrorHandler:
Call LogErrorEx("Error in: ConvertDocToRtfFile", SEVERITY_HIGH, doc)
Error Err, Error$
End Sub

%REM
Sub ConvertDocumentToPdf
Description: Converts a NotesDocument to an PDF-Document and saves it under the filePath
Needs an COM-Instace of a Word Application created with:
Dim word As Variant
Set word = CreateObject("Word.Application")
Generates and removes some temporary Files while Working
%END REM
Public Sub ConvertDocumentToPdf(doc As NotesDocument, word As Variant, filePath As String)
Dim wordDoc As Variant

' On Error GoTo ErrorHandler
Call ConvertDocToRtfFile(doc, filePath & ".rtf")
'http://msdn.microsoft.com/en-us/library/office/bb216319(v=office.12).aspx
Set wordDoc = word.Documents.Open(filePath & ".rtf", False, True, False)
'http://msdn.microsoft.com/en-us/library/office/bb256835(v=office.12).aspx
Call wordDoc.ExportAsFixedFormat(filePath, wdExportFormatPDF, False, wdExportOptimizeForPrint, wdExportAllDocument, 0, 9999999, wdExportDocumentContent, True, True, wdExportCreateHeadingBookmarks, True, True, True, Nothing)
Call wordDoc.Close(0)
Kill filePath & ".rtf"
Exit Sub
ErrorHandler:
Call LogErrorEx("Error in: ConvertDocumentToPdf", SEVERITY_HIGH, doc)
Error Err, Error$
End Sub

%REM
Function ConvertItemToRtfFile
Description: Converts an NotesRichTextItem to an RTF-Document and saves it under the filePath
Generates and removes a temporary File while Working
%END REM
Public Sub ConvertItemToRtfFile(item As NotesRichTextItem, filePath As String)
' On Error GoTo ErrorHandler

Dim fileSize As Long
Dim doc As NotesDocument

Set doc = item.Parent
Call MailGetMessageBodyComposite(doc.handle , "Body", filePath & ".cd", fileSize)
Call ExportRTF(filePath & ".cd", 0, 0, "", filePath)

Kill filePath & ".cd"
Exit Sub
ErrorHandler:
Call LogErrorEx("Error in: ConvertItemToRtfFile", SEVERITY_MEDIUM, doc)
Error Err, Error$
End Sub

Then the agent that calls this script library:

%REM
Agent convert to pdf
Created Sep 9, 2016 by Betsy Thiede/DEV/SPRGFLD/CSCI
Description: Comments for Agent
%END REM
Option Public
Option Declare
Use "PdfConverter"

Sub Initialize
Dim Session As New NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Dim filePath As String
Dim objWord As Variant
Set objWord = CreateObject("Word.Application")
Set db = session.Currentdatabase
Set collection = db.Unprocesseddocuments
If collection.count = 0 Then
Exit sub
End If
Set doc = collection.Getfirstdocument()
Do Until doc Is Nothing
filePath = "C:\Users\bthiede\Documents\test_files\" & doc.Universalid
'Call ConvertDocToRtfFile(doc , filePath)
Call ConvertDocumentToPdf(doc, objWord, filePath)
Set doc = collection.Getnextdocument(doc)
Loop
End Sub





Feedback number WEBBADMLBV created by ~Hal Quetlu on 09/09/2016

Status: Open
Comments:

Notes Document to PDF (~Hal Quetlu 9.Sep.16)
. . I personally would use a print driv... (~Fritz Ekfoober... 9.Sep.16)
. . . . Hmm..I have no idea how I would go ... (~Hal Quetlu 9.Sep.16)
. . . . . . Not particularly easy, either (~Sigmund Umwema... 11.Sep.16)
. . . . . . It is worth the trouble to try this... (~Sigmund Umwema... 12.Sep.16)
. . . . . . Actually, I was too vague. (~Sigmund Umwema... 16.Sep.16)
. . There are numerous issues with Word... (~Sigmund Umwema... 11.Sep.16)
. . This works for us (~Sigmund Zekfre... 27.Sep.16)
. . . . Thank you (~Hal Quetlu 30.Sep.16)
. . Third-party tools (~Fred Asatumibu... 12.Sep.16)
. . . . Third party tools (~Wei Desfreebur... 12.Sep.16)
. . Easily export to PDF, Word, HTML (~Lorraine Nimji... 13.Oct.16)




Printer-friendly

Search this forum

Member Tools


RSS Feeds

 RSS feedsRSS
All forum posts RSS
All main topics RSS